package com.example.util;

import com.example.init.ServerInit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class PropertiesUtil {

    private static final Logger log = LoggerFactory.getLogger(PropertiesUtil.class);

    private static final String applicationProperties = "/resources/application.properties";

    public static final String rootDir = System.getProperty("user.dir");

    public static final String staticDir = rootDir + File.separator + "dist" + File.separator;

    private static Properties properties = null;

    static {
        try {
            InputStream inputStream = PropertiesUtil.class.getResourceAsStream(applicationProperties);
            properties = new Properties();
            properties.load(inputStream);
            log.info("读取配置文件完成");
        } catch (IOException e) {
            log.error("加载配置文件失败", e);
            throw new RuntimeException(e);
        }
    }

    public static String getProperty(String key) {

        return properties.getProperty(key);
    }

}
